package br.com.jf.core;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class SaxReaderJF extends DefaultHandler{

	private boolean projectConfigurationFlag=false;
	private boolean scannerFlag=false;
	private boolean packageFlag=false;
	private boolean messagesFlag=false;
	private boolean configFlag=false;
	private boolean flagHandlerName = false;
	private boolean flagHandlerClass = false;
	private boolean flagExceptionHandler = false;
	private List<String> listaPacotes = new ArrayList<String>();
	private String baseNameMessages;
	private String varMessages;
	private String handlerClass;
	
	@Override
	public void startElement(String arg0, String arg1, String qName,
			Attributes atributo) throws SAXException {
	
		if(qName.trim().equalsIgnoreCase("project-configuration")){
			
			projectConfigurationFlag = true;
		}
		else if(qName.trim().equalsIgnoreCase("scanner")){
			
			scannerFlag = true;
		}
		else if(qName.trim().equalsIgnoreCase("package")){
			
			listaPacotes.add(atributo.getValue("url"));
			
			packageFlag = true;
		}
		else if(qName.trim().equalsIgnoreCase("messages")){
			
			messagesFlag = true;
		}
		else if(qName.trim().equalsIgnoreCase("config")){
			
			baseNameMessages = atributo.getValue("basename");
			varMessages = atributo.getValue("var");
			
			configFlag = true;
		}
		else if(qName.trim().equalsIgnoreCase("exceptionHandler")){
			
			flagExceptionHandler = true;
			
		}
		
		else if(qName.trim().equalsIgnoreCase("handler-class")){
			
			flagHandlerClass = true;
		}
		
	}

	
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {

		
	}
	
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		
		//Recupera o valor da TAG "handler-class"
		if(flagHandlerClass){
			
			handlerClass = new String(ch,start,length);
			
			flagHandlerClass = false;
		}
	}


	public List<String> getListaPacotes() {
		return listaPacotes;
	}


	public void setListaPacotes(List<String> listaPacotes) {
		this.listaPacotes = listaPacotes;
	}


	public String getBaseNameMessages() {
		return baseNameMessages;
	}


	public void setBaseNameMessages(String baseNameMessages) {
		this.baseNameMessages = baseNameMessages;
	}


	public String getVarMessages() {
		return varMessages;
	}


	public void setVarMessages(String varMessages) {
		this.varMessages = varMessages;
	}
	

	public String getHandlerClass() {
		return handlerClass;
	}


	public void setHandlerClass(String handlerClass) {
		this.handlerClass = handlerClass;
	}
	

}
